Skip to content

feat(effect): Export layers for browser | setTracer in buildEffectTracer#19816

Merged
JPeer264 merged 2 commits intojp/add-effect-sdkfrom
jp/add-effect-sdk-stack/8
Mar 17, 2026
Merged

feat(effect): Export layers for browser | setTracer in buildEffectTracer#19816
JPeer264 merged 2 commits intojp/add-effect-sdkfrom
jp/add-effect-sdk-stack/8

Conversation

@JPeer264
Copy link
Member

This changes three things in one go:

  • Export SentryEffectTracer, SentryEffectLogger and SentryEffectMetricsLayer for bundle sizes in the browser (and node if they want to go that route)
  • Respect tracesSampleRate when using Sentry.effectLayer, so tracing is only added when needed
  • Moving setTracer outside of SentryEffectTracerLayer to make it Effect native, where users could call setTracer on their own if they want to

@JPeer264 JPeer264 requested a review from Lms24 March 16, 2026 12:02
@JPeer264 JPeer264 self-assigned this Mar 16, 2026
* Effect Layer that sets up the Sentry tracer for Effect spans.
*/
export const SentryEffectTracerLayer: Layer.Layer<never, never, never> = setTracer(makeSentryTracer());
export const SentryEffectTracer = makeSentryTracer();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The export SentryEffectTracerLayer was renamed, but the test file tracer.test.ts was not updated and still imports the old, non-existent name, which will break tests.
Severity: HIGH

Suggested Fix

Update packages/effect/test/tracer.test.ts to import the new SentryEffectTracer and wrap it with setTracer before providing it to the Effect in the tests, for example: Effect.provide(setTracer(SentryEffectTracer)). Also, remove the unused setTracer import from packages/effect/src/tracer.ts.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/effect/src/tracer.ts#L201

Potential issue: The refactoring in `packages/effect/src/tracer.ts` replaced the `Layer`
export `SentryEffectTracerLayer` with a raw `Tracer` object named `SentryEffectTracer`.
However, the corresponding test file, `packages/effect/test/tracer.test.ts`, was not
updated. It continues to import `SentryEffectTracerLayer`, which no longer exists. This
import will resolve to `undefined` at runtime, causing all 16 test cases that call
`Effect.provide(SentryEffectTracerLayer)` to fail with a runtime error. Additionally, an
unused import for `setTracer` remains in `tracer.ts`.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Conditional tracing breaks existing test expecting Sentry tracer
    • Updated the test to pass tracesSampleRate: 1.0 to createClient() so hasSpansEnabled returns true and the Sentry tracer is properly added.
  • ✅ Fixed: No new tests for conditional tracing behavior
    • Added two new tests to verify conditional tracing behavior: one for when spans are disabled (no tracesSampleRate) and one for when tracesSampler is set.

Create PR

Or push these changes by commenting:

@cursor push a9719126b9
Preview (a9719126b9)
diff --git a/packages/effect/src/index.client.ts b/packages/effect/src/index.client.ts
--- a/packages/effect/src/index.client.ts
+++ b/packages/effect/src/index.client.ts
@@ -6,6 +6,6 @@
 export { effectLayer, init } from './client/index';
 export type { EffectClientLayerOptions } from './client/index';
 
-export { SentryEffectTracer } from './tracer';
+export { SentryEffectTracer, SentryEffectTracerLayer } from './tracer';
 export { SentryEffectLogger } from './logger';
 export { SentryEffectMetricsLayer } from './metrics';

diff --git a/packages/effect/src/index.server.ts b/packages/effect/src/index.server.ts
--- a/packages/effect/src/index.server.ts
+++ b/packages/effect/src/index.server.ts
@@ -3,6 +3,6 @@
 export { effectLayer, init } from './server/index';
 export type { EffectServerLayerOptions } from './server/index';
 
-export { SentryEffectTracer } from './tracer';
+export { SentryEffectTracer, SentryEffectTracerLayer } from './tracer';
 export { SentryEffectLogger } from './logger';
 export { SentryEffectMetricsLayer } from './metrics';

diff --git a/packages/effect/src/tracer.ts b/packages/effect/src/tracer.ts
--- a/packages/effect/src/tracer.ts
+++ b/packages/effect/src/tracer.ts
@@ -199,3 +199,8 @@
  * Effect Layer that sets up the Sentry tracer for Effect spans.
  */
 export const SentryEffectTracer = makeSentryTracer();
+
+/**
+ * Effect Layer that sets up the Sentry tracer for Effect spans.
+ */
+export const SentryEffectTracerLayer: Layer.Layer<never, never, never> = setTracer(SentryEffectTracer);

diff --git a/packages/effect/test/buildEffectLayer.test.ts b/packages/effect/test/buildEffectLayer.test.ts
--- a/packages/effect/test/buildEffectLayer.test.ts
+++ b/packages/effect/test/buildEffectLayer.test.ts
@@ -136,8 +136,32 @@
           }),
         );
         startInactiveSpanSpy.mockRestore();
+      }).pipe(Effect.provide(buildEffectLayer({}, createClient({ tracesSampleRate: 1.0 })))),
+    );
+
+    it.effect('layer does not enable tracing when tracesSampleRate is not set', () =>
+      Effect.gen(function* () {
+        const startInactiveSpanSpy = vi.spyOn(sentryCore, 'startInactiveSpan');
+        const result = yield* Effect.withSpan('test-span-no-tracing')(Effect.succeed('not-traced'));
+        expect(result).toBe('not-traced');
+        expect(startInactiveSpanSpy).not.toHaveBeenCalled();
+        startInactiveSpanSpy.mockRestore();
       }).pipe(Effect.provide(buildEffectLayer({}, createClient()))),
     );
+
+    it.effect('layer enables tracing when tracesSampler is set', () =>
+      Effect.gen(function* () {
+        const startInactiveSpanSpy = vi.spyOn(sentryCore, 'startInactiveSpan');
+        const result = yield* Effect.withSpan('test-sampler-span')(Effect.succeed('sampled'));
+        expect(result).toBe('sampled');
+        expect(startInactiveSpanSpy).toHaveBeenCalledWith(
+          expect.objectContaining({
+            name: 'test-sampler-span',
+          }),
+        );
+        startInactiveSpanSpy.mockRestore();
+      }).pipe(Effect.provide(buildEffectLayer({}, createClient({ tracesSampler: () => true })))),
+    );
   });
 
   describe('with additional options', () => {

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.64 kB added added
@sentry/browser - with treeshaking flags 24.14 kB added added
@sentry/browser (incl. Tracing) 42.62 kB added added
@sentry/browser (incl. Tracing, Profiling) 47.28 kB added added
@sentry/browser (incl. Tracing, Replay) 81.42 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 71 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 86.12 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 98.37 kB added added
@sentry/browser (incl. Feedback) 42.45 kB added added
@sentry/browser (incl. sendFeedback) 30.31 kB added added
@sentry/browser (incl. FeedbackAsync) 35.36 kB added added
@sentry/browser (incl. Metrics) 26.92 kB added added
@sentry/browser (incl. Logs) 27.07 kB added added
@sentry/browser (incl. Metrics & Logs) 27.74 kB added added
@sentry/react 27.39 kB added added
@sentry/react (incl. Tracing) 44.95 kB added added
@sentry/vue 30.08 kB added added
@sentry/vue (incl. Tracing) 44.48 kB added added
@sentry/svelte 25.66 kB added added
CDN Bundle 28.27 kB added added
CDN Bundle (incl. Tracing) 43.5 kB added added
CDN Bundle (incl. Logs, Metrics) 29.13 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 44.34 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 68.2 kB added added
CDN Bundle (incl. Tracing, Replay) 80.32 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.22 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.86 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.76 kB added added
CDN Bundle - uncompressed 82.56 kB added added
CDN Bundle (incl. Tracing) - uncompressed 128.5 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.43 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 131.37 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 209.06 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 245.35 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 248.21 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 258.26 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 261.11 kB added added
@sentry/nextjs (client) 47.37 kB added added
@sentry/sveltekit (client) 43.07 kB added added
@sentry/node-core 56.34 kB added added
@sentry/node 173.19 kB added added
@sentry/node - without tracing 96.35 kB added added
@sentry/aws-serverless 113.34 kB added added

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@JPeer264 JPeer264 requested a review from s1gr1d March 17, 2026 09:47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoring this for the review since we remove it in #19823

@JPeer264 JPeer264 merged commit 7ed7721 into jp/add-effect-sdk Mar 17, 2026
34 checks passed
@JPeer264 JPeer264 deleted the jp/add-effect-sdk-stack/8 branch March 17, 2026 10:31
JPeer264 added a commit that referenced this pull request Mar 17, 2026
…cer (#19816)

This changes three things in one go:

- Export `SentryEffectTracer`, `SentryEffectLogger` and
`SentryEffectMetricsLayer` for bundle sizes in the browser (and node if
they want to go that route)
- Respect `tracesSampleRate` when using `Sentry.effectLayer`, so tracing
is only added when needed
- Moving `setTracer` outside of `SentryEffectTracerLayer` to make it
Effect native, where users could call `setTracer` on their own if they
want to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants